<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>重绘图表或图形</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        text-align: center;
        margin: 0;
        padding: 50px;
      }

      canvas {
        background-color: #f3f3f3;
        margin-top: 20px;
      }
    </style>
  </head>
  <body>
    <h1>Resize to Redraw Chart</h1>
    <canvas id="myChart"></canvas>
    <script>
      const canvas = document.getElementById("myChart");
      const ctx = canvas.getContext("2d");
      function drawChart() {
        const width = window.innerWidth * 0.8;
        const height = window.innerHeight * 0.5;
        canvas.width = width;
        canvas.height = height;
        console.log(canvas.width, canvas.height);
        // 简单绘制一个矩形示例
        ctx.fillStyle = "blue";
        ctx.fillRect(0, 0, width, height);
        ctx.fillStyle = "white";
        ctx.fillText("Chart Redrawn", width / 2 - 50, height / 2);
      }
      window.addEventListener("resize", drawChart);
      drawChart();
    </script>
  </body>
</html>
